package t20250228_sqlparse;

import org.apache.flink.streaming.api.environment.LocalStreamEnvironment;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
import t20250228_sqlparse.lineage.LineageContext;
import t20250228_sqlparse.lineage.LineageRel;
import t20250228_sqlparse.lineage.SingleSql;
import t20250228_sqlparse.lineage.SqlUtil;

import java.util.List;

public class Test1 {

    public static void main(String[] args) {
        LocalStreamEnvironment localEnv = StreamExecutionEnvironment.createLocalEnvironment();
        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(localEnv);



        LineageContext lineageContext = new LineageContext(tableEnv);
        List<SingleSql> split = SqlUtil.split(Sql.SQL);
        List<LineageRel> lineageRels = lineageContext.analyzeLineage(split);
        for (LineageRel lineageRel : lineageRels) {
            System.out.println(lineageRel.getSourceTablePath() + "." +  lineageRel.getSourceColumn() + " -> " + lineageRel.getTargetTablePath() + "." + lineageRel.getTargetColumn());
        }

    }
}
